package algorithm;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName Solution
 * @Author 刘正星
 * @Date 2021/6/21 下午11:26
 * @Description
 */
public class Solution {

    /**
     * 回文数
     * @param x
     * @return
     */

    public static boolean isPalindrome(int x){
       /* int old = x;

        int num = 0;

        while (x!=0){

            num = num * 10 + x % 10;

            x = x/10;
        }
        return old== num;*/

        if (x < 0 || (x %10 ==0 && x !=0 )){
            return false;
        }
        int reserveNum = 0;
        while (x > reserveNum){
            reserveNum = reserveNum * 10 + x % 10;
            x= x / 10;
        }
        return x == reserveNum || x  == reserveNum /10;

    }

    /**
     * 一个数倒置   1232  -->  2321
     * @param x
     * @return
     */

    public  static int reserve(int x){

        int old = x;

        int num = 0;

        while (x!=0){

            num = num * 10 + x % 10;

            x = x / 10;
        }

        return num;
    }

    /**
     * 罗马数字转整数
     * @param s
     * @return
     */

   static Map<Character,Integer> map = new HashMap<>(){{
        put('I',1);
        put('V',5);
        put('X',10);
        put('L',50);
        put('C',100);
        put('D',500);
        put('M',1000);
    }};

    public static   int romantoInt(String s){

        int n = s.length();

        int sum = 0;

        for (int i = 0; i < n; i++) {
            int value = map.get(s.charAt(i));
            if (i < n -1 && value < map.get(s.charAt(i+1))){
                sum -= value;
            }else{
                sum += value;
            }

        }

      return sum;

    }

    public static void main(String[] args) {
        System.out.println(isPalindrome(2457));

        System.out.println(isPalindrome(2552));

        System.out.println(isPalindrome(212));
    }
}
